home *** CD-ROM | disk | FTP | other *** search
- Path: crchh327.rich.bnr.ca!jobell
- From: jobell@bnr.ca (Bret Bieghler)
- Newsgroups: comp.lang.c++
- Subject: Re: Diff between const str& and const str*
- Date: 19 Feb 1996 22:01:46 GMT
- Organization: Bell-Northern Research Ltd.
- Message-ID: <4gas0a$rj0@crchh327.rich.bnr.ca>
- References: <4g93d4$ej4@newsstand.cit.cornell.edu>
- NNTP-Posting-Host: crchh524.rich.bnr.ca
-
- In article <4g93d4$ej4@newsstand.cit.cornell.edu>,
- Warren Ouyang <wo10@cornell.edu> wrote:
- >Hello all, I was wondering... in C++, is there a difference between
- >"const str&" and "const str*" as function parameters? (str is a class).
- >Thanks for any help!
- >
- >Warren
-
- One is a reference, the other a pointer.
-
- void foobar (const int& x, const int* y)
- {
- cout << x << endl; // equivalent to cout << *y << endl;
- cout << y << endl;
- }
-
- void main (void)
- {
- int a = 5;
-
- foobar (a, &a);
- }
-
- gives
-
- 5
- 0xabcdabcd (some address)
-
- JB
-
- --
- Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
- Northern Telecom / Bell-Northern Research
- "What? Evacuate now, in our moment of triumph? Surely you overestimate their chances."
-